/*
 * @(#)CustomMethodLoader.java $version 2010. 8. 11
 *
 * Copyright 2007-2010 NHN Corp. All rights Reserved. 
 * NHN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
 */
package com.nhncorp.usf.macro.method;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.w3c.dom.Node;

import com.nhncorp.lucy.common.util.XMLDOMUtil;

/**
 * @author Web Platform Development Team
 */
public class CustomMethodLoader implements MethodInfoLoader {
    Log log = LogFactory.getLog(CustomMethodLoader.class);

    private List<MethodInfo> methodInfos = new ArrayList<MethodInfo>();

    /**
     *
     * @param configurationNode the Node
     * @return the method information
     */
    @SuppressWarnings("deprecation")
    public List<MethodInfo> load(Node configurationNode) {

        log.debug("Template MethodInfo Loading...(custom)");

        Iterator<Node> namespaceIter = XMLDOMUtil.getNodeIterator(configurationNode,
                                                                  "usf-macro:methods/usf-macro:namespace");

        while (namespaceIter.hasNext()) {
            Node namespaceNode = namespaceIter.next();
            String namespace = XMLDOMUtil.getValue(namespaceNode, "@value");
            Iterator<Node> methodIter = XMLDOMUtil.getNodeIterator(namespaceNode, "usf-macro:method");

            while (methodIter.hasNext()) {
                Node methodNode = methodIter.next();
                String className = XMLDOMUtil.getValue(methodNode, "@class");
                String methodName = XMLDOMUtil.getValue(methodNode, "@name");
                methodInfos.add(new MethodInfo(methodName, className, namespace));
            }
        }

        return methodInfos;
    }
}
